package probability;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author antonio
 */

import java.util.*;
import java.lang.*;


public class HashProbabilityHandler {

    private Hashtable hashProbability;

    public Hashtable getHashtable()
    {
        return this.hashProbability;
    }

    public HashProbabilityHandler(Hashtable hashProbability)
    {
        this.hashProbability = hashProbability;
        this.initializeHash();
    }

    public void initializeHash()
    {
        for(int i=0; i<100; i++)
        {
            this.hashProbability.put(i, new Integer(0));     //key=segnale   value=frequenza segnale
        }

        //aggiungo il numero totale di segnali rilevati

        this.hashProbability.put(100, new Integer(0));
    }

    public void updateProbabilityValue(int signal, String frequency)
    {
        Integer oldFrequency = (Integer)this.hashProbability.get(signal);
        Integer tmpFrequency = new Integer(frequency);
        Integer newFrequency = oldFrequency + tmpFrequency;

        

        this.hashProbability.remove(signal);
        this.hashProbability.put(signal, newFrequency);

        
    }

    public void updateTotalValue(String total)
    {
        Integer oldTotal = (Integer)this.hashProbability.get(100);
        Integer tmpTotal = new Integer(total);
        Integer newTotal = oldTotal + tmpTotal;

        this.hashProbability.remove(100);
        this.hashProbability.put(100, newTotal);

    }

    public void setTotalValue(String total)
    {
        Integer newTotal = new Integer(total);

        this.hashProbability.remove(100);
        this.hashProbability.put(100, newTotal);
    }

}
